<?php

namespace App\Http\Resources\Agent;

use App\model\agent\Agent;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class AgentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'code'=>0,
            'message'=>'查询成功',
            'data'=>[
                'user_id'=>$this->id,
                'name'=>$this->name,
                'mobile'=>$this->mobile,
                'department'=>$this->department->name,
                'icon'=>Storage::url($this->department->icon),
                'position_id'=>$this->position->name,
                'avatar'=>\Storage::url($this->avatar),
                'address'=>$this->address ,
                'fendian_name'=>$this->fendian_name,
                'mobile_format'=>substr($this->mobile,0,3).'-'.substr($this->mobile,3,4).'-'.substr($this->mobile,7,4),
                'is_zong'=>$this->is_zong==Agent::ZONG ? '总部地址' : '分部地址',
                'lat'=>$this->lat,
                'lng'=>$this->lng
            ]
        ];
    }
}
